package com.yb0os1.core;

import com.yb0os1.beans.BeanDefinition;
import com.yb0os1.beans.BeanFactory;
import org.dom4j.Element;

public class XmlBeanDefinitionReader {
    private BeanFactory beanFactory;
    public XmlBeanDefinitionReader(BeanFactory beanFactory){
        this.beanFactory = beanFactory;
    }
    public void loadBeanDefinitions(Resource resource){
        while (resource.hasNext()){
            Element configObject = (Element)resource.next();
            BeanDefinition beanDefinition = new BeanDefinition();
            beanDefinition.setId(configObject.attributeValue("id"));
            beanDefinition.setClassName(configObject.attributeValue("class"));
            beanFactory.registerBeanDefinition(beanDefinition.getId(),beanDefinition);
        }
    }
}
